package com.fsh.subject.infra.rpc;

import com.fsh.auth.api.UserFeignService;
import com.fsh.auth.entity.AuthUserDTO;
import com.fsh.auth.entity.Result;
import com.fsh.subject.infra.rpc.entity.UserInfo;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 作者：fsh
 * 日期：2023/12/06
 * <p>
 * 描述：用户 RPC。  调用其他服务的功能，就要调用其他服务提供的接口(当然先导入其他服务)
 */
@Component
public class UserRpc {
    @Resource
    private UserFeignService userFeignService;

    public UserInfo getUserInfo(String userName){
        AuthUserDTO authUserDTO=new AuthUserDTO();
        authUserDTO.setUserName(userName);
        //远程调用
        Result<AuthUserDTO> result = userFeignService.getUserInfo(authUserDTO);
        //调用失败
        UserInfo userInfo=new UserInfo();
        if (!result.getSuccess()){
            return userInfo;
        }
        //调用成功
        AuthUserDTO dto = result.getData();
        userInfo.setUserName(dto.getUserName());
        userInfo.setNickName(dto.getNickName());
        userInfo.setAvatar(dto.getAvatar());
        return userInfo;
    }

}
